package com.editor.utils;

import javax.swing.*;

// Класс помогающий работать с схемами замещения
public class EquivalentCircuit {
	/**
	 * Инициализация таблицы параметров
	 * @param name = название элемента
	 */
	
	public static JTable initTParams(String name){
        //JTable table = null;
        JTable table = new JTable();
		if(name.equals("ismaGenerator") && ParamsAndCondsTableModel.current.equals("Схема 1"))
			table = new JTable(ParamsAndCondsTableModel.DATA_GENERATOR, ParamsAndCondsTableModel.COLUMN_NAMES);
		else if(name.equals("ismaGenerator") && ParamsAndCondsTableModel.current.equals("Схема 2"))
			table = new JTable(ParamsAndCondsTableModel.DATA_SCHEME, ParamsAndCondsTableModel.COLUMN_NAMES);
		
		else if(name.equals("ismaTransform"))
			table = new JTable(ParamsAndCondsTableModel.DATA_TRANSFORM, ParamsAndCondsTableModel.COLUMN_NAMES);
		
		else if(name.equals("ismaCommonLoad"))
			table = new JTable(ParamsAndCondsTableModel.DATA_NAGR, ParamsAndCondsTableModel.COLUMN_NAMES);
		else if(name.equals("boldEWEdge"))
			if (ParamsAndCondsTableModel.current.equals("Схема 1"))
                table = new JTable(ParamsAndCondsTableModel.DATA_LAP, ParamsAndCondsTableModel.COLUMN_NAMES);
            else if (ParamsAndCondsTableModel.current.equals("Схема 2"))
                table = new JTable(ParamsAndCondsTableModel.DATA_LAP2, ParamsAndCondsTableModel.COLUMN_NAMES);

		else if(table == null)
			table = new JTable(ParamsAndCondsTableModel.DATA_EMPTY, ParamsAndCondsTableModel.COLUMN_NAMES);
		//table.setPreferredScrollableViewportSize(new Dimension(500, 70));
		//table.setFillsViewportHeight(true);
		return table;
	}
	
	/**
	 * Инициализация таблицы начальных условий
	 * @param name = название элемента
	 */
	
	public static JTable initIConditions(String name){
        //JTable table = null;
        JTable table = new JTable();
		if(name.equals("ismaGenerator") && ParamsAndCondsTableModel.current.equals("Схема 1"))
			table = new JTable(ParamsAndCondsTableModel.INIT_CONDITION_GENERATOR, ParamsAndCondsTableModel.COLUMN_NAMES);
		else if(name.equals("ismaGenerator") && ParamsAndCondsTableModel.current.equals("Схема 2"))
			table = new JTable(ParamsAndCondsTableModel.INIT_CONDITION_SCHEME, ParamsAndCondsTableModel.COLUMN_NAMES);
		
		else if(name.equals("ismaTransform"))
			//return null;
		    return table;
		else if(name.equals("ismaCommonLoad"))
			table = new JTable(ParamsAndCondsTableModel.INIT_CONDITION_NAGR, ParamsAndCondsTableModel.COLUMN_NAMES);
		else if(name.equals("boldEWEdge"))
            if (ParamsAndCondsTableModel.current.equals("Схема 1"))
			    table = new JTable(ParamsAndCondsTableModel.INIT_CONDITION_LAP, ParamsAndCondsTableModel.COLUMN_NAMES);
            else if (ParamsAndCondsTableModel.current.equals("Схема 2"))
                table = new JTable(ParamsAndCondsTableModel.INIT_CONDITION_LAP2, ParamsAndCondsTableModel.COLUMN_NAMES);
            //return null;
			//return table;

		else if(table == null)
			table = new JTable(ParamsAndCondsTableModel.DATA_EMPTY, ParamsAndCondsTableModel.COLUMN_NAMES);
		//table.setPreferredScrollableViewportSize(new Dimension(500, 70));
		//table.setFillsViewportHeight(true);
		return table;
	}
	
	/**
	 * Рисунок схемы замещения
	 * @param name = название элемента
	 */
	
	public static JLabel getImage(String name, Class clas){
		ImageIcon image = null;
		JLabel label;
		if(name.equals("ismaGenerator") && ParamsAndCondsTableModel.current.equals("Схема 1"))
			image = new ImageIcon(clas.getResource("/com/mxgraph/examples/swing/images/image_generator.png"));
		else if(name.equals("ismaGenerator") && ParamsAndCondsTableModel.current.equals("Схема 2"))
			image = new ImageIcon(clas.getResource("/com/mxgraph/examples/swing/images/image_scheme.png"));
		else if(name.equals("ismaTransform"))
			image = new ImageIcon(clas.getResource("/com/mxgraph/examples/swing/images/image_transform.png"));
		else if(name.equals("ismaCommonLoad"))
			image = new ImageIcon(clas.getResource("/com/mxgraph/examples/swing/images/image_nagruzka.png"));
		else if(name.equals("boldEWEdge"))
			if (ParamsAndCondsTableModel.current.equals("Схема 1"))
			    image = new ImageIcon(clas.getResource("/com/mxgraph/examples/swing/images/line.png"));
            else if (ParamsAndCondsTableModel.current.equals("Схема 2"))
                image = new ImageIcon(clas.getResource("/com/mxgraph/examples/swing/images/line2.png"));
		label = new JLabel(image);
		return label;
	}
}
